package com.egao.orderB.controller2;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.orderB.entity.City;
import com.egao.orderB.service.CityService;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;


/**
 *
 * 市
 * @author : Doman
 * @date : 2020-10-20 15:32:26
 * @version ：1.0
 */

//@Api(tags = "市")
//@RestController
//@RequestMapping("/api/orderB/city")
public class CityController extends BaseController {

	@Autowired
	private CityService cityService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:city:list')")
    @OperLog(value = "市", desc = "分页查询")
    @ApiOperation("分页查询市")
    @ApiPageParam
    @PostMapping("/page")
    public JsonResult page(PageResult2<T> page, City city) throws Exception{
        return cityService.list(page, city, getLoginUser());
    }

    /**
     * 查询全部市
     */
    @PreAuthorize("hasAuthority('orderB:city:list')")
    @OperLog(value = "市", desc = "查询全部")
    @ApiOperation("查询全部市")
    @PostMapping("/list")
    public JsonResult list(City city){
        return cityService.list(city, getLoginUser());
    }

    /**
     * 根据id查询市
     */
    @PreAuthorize("hasAuthority('orderB:city:list')")
    @OperLog(value = "市", desc = "根据id查询")
    @ApiOperation("根据id查询市")
    @PostMapping("/get")
    public JsonResult get(City city) {
        return cityService.getById(city);
		// 使用关联查询
        //PageParam<city> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<city> records = cityService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加市
     */
    @PreAuthorize("hasAuthority('orderB:city:save')")
    @OperLog(value = "市", desc = "添加", param = false, result = true)
    @ApiOperation("添加市")
    @PostMapping("/save")
    public JsonResult save(Model model, City city) {
        return cityService.save(city, getLoginUser());
    }

    /**
     * 修改市
     */

    @PreAuthorize("hasAuthority('orderB:city:update')")
    @OperLog(value = "市", desc = "修改", param = false, result = true)
    @ApiOperation("修改市")
    @PostMapping("/update")
    public JsonResult update(Model model, City city) {
        return cityService.update(city, getLoginUser());
    }

    /**
     * 删除市
     */
    @PreAuthorize("hasAuthority('orderB:city:remove')")
    @OperLog(value = "市", desc = "删除", result = true)
    @ApiOperation("删除市")
    @PostMapping("/remove")
    public JsonResult remove(City city ) {
        return cityService.remove(city, getLoginUser());
    }

    /**
     * 批量添加市
     */
    /**@RequiresPermissions("orderB:city:save")
    @OperLog(value = "市", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<City> list) {
        if (cityService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改市
     */
    /**@RequiresPermissions("orderB:city:update")
    @OperLog(value = "市", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<City> batchParam) {
        if (batchParam.update(cityService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除市
     */
    /**@RequiresPermissions("orderB:city:remove")
    @OperLog(value = "市", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (cityService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
